package cn.java78.jdbc;

import cn.myschool.util.DBUtil;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class MetaData {
    public static void main(String[] args) throws SQLException {
        Connection con = DBUtil.getConnection();
        DatabaseMetaData metaData = con.getMetaData();
        System.out.println("数据库名字：" + metaData.getDatabaseProductName());
        System.out.println("驱动名字：" + metaData.getDriverName());
        System.out.println("版本：" + metaData.getDatabaseProductVersion
                ());
        System.out.println("函数：" + metaData.getSystemFunctions()
                );
        PreparedStatement ps = con.prepareStatement("select * from s_student");
        ResultSet rs = ps.executeQuery();
        ResultSetMetaData rm = rs.getMetaData();
        //
        for (int i = 1; i <= rm.getColumnCount(); i++) {
            System.out.println(rm.getColumnLabel(i) + ",类型:" + rm.getColumnTypeName(i) + ",java类型：" + rm.getColumnClassName(i));
        }
        DBUtil.close(rs, ps, con);
    }
}
